import serial
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import serial.tools.list_ports

def find_rfid_port():
    ports = serial.tools.list_ports.comports()
    for port in ports:
        if "RFID" in port.description:
            return port.device
    return None

rfid_port = find_rfid_port()
if rfid_port is None:
    print("RFID读卡器未找到")
else:
    print("RFID读卡器已找到，端口号为：", rfid_port)

# 创建一个串行端口连接，替换'/dev/ttyUSB0'为你的RFID读卡器的端口
ser = serial.Serial('/dev/ttyUSB0', 9600)

# 读取RFID数据
rfid_data = ser.readline().decode('utf-8').strip()

# 创建一个新的selenium浏览器实例
driver = webdriver.Firefox()

# 跳转到百度首页
driver.get('https://www.baidu.com')

# 找到搜索框并输入RFID数据
search_box = driver.find_element_by_name('wd')
search_box.send_keys(rfid_data)

# 提交搜索请求
search_box.send_keys(Keys.RETURN)